home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* These procedures are used to create windows,write,and clear. */
- /* I use windows in my programs and TurboC did not support them. */
- /* The routines can be used by you but if you use them I only ask */
- /* that I get a little credit for my work. */
- /* This is my first real program in C if you find bugs let me know thanks. */
- /* writted by */
- /* Charles G. Nemer */
- /* 4538 Westlake Dr. */
- /* Garlend TX. 75043 */
- /* 214-226-9364 */
- /****************************************************************************/
-
- #include<stdio.h>
- #include<alloc.h>
- #include<dos.h>
- #include<stdarg.h>
-
- #define MONO 0xB0000000 /* address of mono screen*/
- #define COLORM 0XB8000000 /* address of color screen*/
- #define TRUE -1
- #define FALSE 0
-
- union REGS reg;struct SREGS sreg; /* setup struct for DOS registrrs */
-
- struct window_data{ /* struct so save window info*/
- unsigned short wrowb,wcolb,wrowe,wcole,wpage,wmode,
- wcurr,wcurc,wcolor,wnum_col,
- bd,bdcolor,wnumber;
- unsigned int size;
- int far * addressave;
- int far *screenbase;
- struct window_data far *last,far *next;
- };
-
-
- int far *screenbase,far *fscreenbase; /* start of screen*/
-
- unsigned short row,rowb,rowe,col,colb,cole,page,lwsize, /* globel varibles*/
- number_of_windows=0,number_max,wcolor,num_col,
- frow,fcol,fpage,fnum_col,frowb,fcolb,frowe,
- fcole,fcolor,scanstart,scanstop,scanstr,scanstp;
-
- struct window_data far *first, far *last, far *present; /* pionters to windo struct*/
-
-
- int fast; /* mono and screen write speed*/
-
- output(int far *dest,int sour,int times);
- foutput(int far *dest,int sour,int times);
- screen(int far * dest,int far *sour,int times);
- fscreen(int far * dest,int far *sour,int times);
- screen_in(int far * dest,int far *sour,int times);
- screen_out(int far *dest,int far *sour,int times);
-
- /*****************************************************************************/
- /* moniter() is to check for the type of moniter controller you have by */
- /* checking the mode you are in you only use this function once. It will set */
- /* things up to use window. the screen write mode will be passed back -1= */
- /* fast screen write 0= slow write so there will be no snow this can be */
- /* changed with set_snow(). */
- /* moniter(); */
- /*****************************************************************************/
-
- monitor()
- {
- reg.h.ah = 0x0F; /* get mode */
- int86(0x10,®,®);
- num_col=reg.h.ah & 0xff; /* set number of col */
- page=reg.h.bh; /* set page */
- rowb=0;colb=0;
- rowe=25,cole=num_col;
- number_of_windows=0;
- if (reg.h.al == 7 )
- { screenbase =(int far *) MONO; fast=TRUE;return(fast);}
- else
- { screenbase =(int far *) COLORM; fast=FALSE;return(fast);}
- }
-
- /*****************************************************************************/
- /* this function is to pick wich function is used when writing to the screen */
- /* if your card displays snow set_snow(-1); */
- /*****************************************************************************/
-
- void set_snow(int m)
- {
- fast=m;
-
- }
-
-
-
- void cursor(int s,int e)
- {
- reg.h.ah = 1; /* set cursor size */
- reg.h.ch = s; /* starting line */
- reg.h.cl = e; /* ending line */
- int86(0x10,®,®);
- }
-
- /*****************************************************************************/
- /* to set the cursor off cursoroff() will set the start line at 32 and */
- /* the ending line at 0. */
- /*****************************************************************************/
- void cursoroff()
- {
- reg.h.ah=3;
- reg.h.bh=0;
- int86(0x10,®,®);
- if(reg.h.ch!=32) /* if not off save*/
- {
- scanstart=reg.h.ch; /* cursor start and*/
- scanstop=reg.h.cl; /* end*/
- }
- reg.h.ah = 1; /* set cursor size */
- reg.h.ch = 32; /* starting line */
- reg.h.cl = 0; /* ending line */
- int86(0x10,®,®);
- }/* end of cursor off*/
-
- /*****************************************************************************/
- /* to set the cursor on cursoroff() will set the start line with scanstart */
- /* and the ending line with scanstop. */
- /*****************************************************************************/
- void cursoron()
- {
- reg.h.ah = 1; /* set cursor size */
- reg.h.ch = scanstart; /* starting line */
- reg.h.cl = scanstop; /* ending line */
- int86(0x10,®,®);
- }/*end of cursor on*/
-
- /*****************************************************************************/
- /* used by window to set the cursor off cursoroff() will set the start line */
- /* at 32 and the ending line at 0. */
- /*****************************************************************************/
- void curoff()
- {
- reg.h.ah=3;
- reg.h.bh=0;
- int86(0x10,®,®);
- scanstr=reg.h.ch;
- scanstp=reg.h.cl;
- reg.h.ah = 1; /* set cursor size */
- reg.h.ch = 32; /* starting line */
- reg.h.cl = 0; /* ending line */
- int86(0x10,®,®);
- }/* end of cursor off*/
-
- /*****************************************************************************/
- /* used by window to set the cursor on cursoroff() will set the start line */
- /* with scanstr and the ending line with scanstp. */
- /*****************************************************************************/
- void curon()
- {
- reg.h.ah = 1; /* set cursor size */
- reg.h.ch = scanstr; /* starting line */
- reg.h.cl = scanstp; /* ending line */
- int86(0x10,®,®);
- }/*end of cursor on*/
-
- /*****************************************************************************/
- /* use this function to set the cursor any where on the screen. */
- /* set_cur(0,0); puts the cursor in the left hand upper corner */
- /*****************************************************************************/
-
- void set_cur(unsigned char row,unsigned char col)
- {
- reg.h.ah = 2; /* set cursor position */
- reg.h.bh = page; /* page */
- reg.h.dh = row;
- reg.h.dl = col;
- int86(0x10,®,®);
- }
-
- /*****************************************************************************/
- /* wgoto() is used to set the cursor with in the window */
- /* wgoto(0,0) puts the cursor in the upper left hand corner */
- /* of the window. */
- /*****************************************************************************/
-
- void wgoto(unsigned char row,unsigned char col)
- {
- row+=rowb;if(row<rowb)row=rowb; /* offset into window*/
- col+=colb;if(col>cole)col=cole;
- reg.h.ah = 2; /* set cursor position */
- reg.h.bh = page; /* page */
- reg.h.dh = row;
- reg.h.dl = col;
- int86(0x10,®,®);
- }
-
- /*****************************************************************************/
- /* after monitor is run you can clear any screen of window */
- /* clrscr(); */
- /*****************************************************************************/
-
- void clrscr()
- {
- int x,y,c;
- int far * address;
- for(x=rowb; x<=rowe; x++)
- {
- address = screenbase + ((x * num_col) + colb);
- for(y=colb;y<=cole;y++)
- {
- c=((wcolor<<8)|0x20);
- if(fast==TRUE) {foutput(address,c,1);}
- else output(address,c,1);
- *address++;
- }
- }
- row=rowb;col=colb;
- set_cur(row,col);
- }
-
-
- /*****************************************************************************/
- /* used by wprintf() */
- /*****************************************************************************/
- void scroll()
- {
-
- unsigned int x,y;
- int c;
- int far * address;
- int far * address_old;
- curoff();
- for(row=rowb;row<rowe;row++)
- {
- address = screenbase + ((row * num_col) + colb);
- address_old = screenbase + (((row+1) * num_col) + colb);
- for(y=colb;y<=cole;y++)
- {
- if(fast==TRUE) {fscreen(address,address_old,1);}
- else screen(address,address_old,1);
- *address++;*address_old++;
- }
- }
- address = screenbase + ((rowe * num_col) + colb);
- for(x=colb;x<=cole;x++)
- {
- c=((wcolor<<8)|0x20);
- if(fast==TRUE) {foutput(address,c,1);}
- else output(address,c,1);
- *address++;
- }
- row=rowe;
- col=colb;
- curon();
- }
-
-
-
- /*****************************************************************************/
- /* used to return the number of windows that have bin made. */
- /*****************************************************************************/
-
- num_of_w()
- {
- return(number_of_windows);
- }
-
- /*****************************************************************************/
- /* used to return the window that you are in */
- /*****************************************************************************/
- int presentw()
- {
- return(present->wnumber);
- }
-
- /*****************************************************************************/
- /* Function set_color is to set the color used by wprintf() */
- /* Include in your progrom #include <screen.h> this will allow */
- /* you to write out the colors use B for background BWHITE all */
- /* constants are upper case set_color(BWHITE|BLACK) will set */
- /* the color to white background and black letters. */
- /* set_color(0x70); */
- /*****************************************************************************/
- void set_color(unsigned short color)
- {
- wcolor=color;
- }
-
- /*****************************************************************************/
- /* save_window() is used by window to move the screen data to a save area */
- /* it also chains this area to the window chain so you can move from window */
- /* to window. The save area first starts with the window struct and then the */
- /* old screen data. The window save area has far pointers that are used to */
- /* access and save area. The number of windows is saved in number_of_windows */
- /*****************************************************************************/
-
- void save_window(int bd, int bdcolor, unsigned int size)
- {
- int far * windstore; /* pointer to save area*/
- int far * temp; /* pointer to save area*/
- unsigned int size1;
- unsigned int x,y;
- unsigned short i,found;
- struct window_data far *windata,far * windtemp,far * windtemp2; /* pointers to window struct*/
- windata=farmalloc(((long)size+sizeof(struct window_data))); /* get scace from memory*/
- windstore=(void far *)(windata+1); /* windstore now points to end of struct +1*/
- if(number_of_windows==0)
- {/*1*/ /* if first window save screen data*/
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- frow = reg.h.dh; /* save cursor row*/
- fcol = reg.h.dl; /* and curcor collum*/
- reg.h.ah = 8; /* get attribute at cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- fcolor = reg.h.ah; /* save color*/
- fnum_col=num_col; /* save number of collums on screen*/
- fpage=page; /* save page*/
- frowb=0;fcolb=0;
- frowe=25;fcole=num_col;
- fscreenbase=screenbase; /* screen base address*/
- windata->last=NULL;last=NULL; /* NULL ends of chain*/
- windata->next=NULL;
- }/*end of if1*/
-
- windata->bd=bd;windata->bdcolor=bdcolor; /* save data on window*/
- windata->size=size;windata->wcolor=wcolor; /* size color*/
- windata->wrowb=rowb;windata->wcolb=colb; /* starting row-col*/
- windata->wrowe=rowe;windata->wcole=cole; /* ending row-col*/
- windata->wpage=page;windata->wmode=getmode(); /* page screen mode*/
- windata->wnum_col=num_col; /* number of col*/
-
- windata->screenbase=(int far *)screenbase; /* screen base address*/
-
-
- /* save screen */
- windata->addressave=windstore;
- for(row=rowb;row<=rowe;row++) /* first row to last*/
- {/*1*/
- temp= screenbase+((row * num_col) + colb); /* address of first col on row*/
- if(fast==TRUE) {fscreen(windstore,temp,(cole-colb)+1);} /* no snow*/
- else screen_out(windstore,temp,(cole-colb)+1); /* snow */
- windstore+=(cole-colb)+1; /* next line*/
- }/*end of for1*/
- number_of_windows++; /* keep track of windows*/
-
- if(number_of_windows>1) /* add struct to chain*/
- {/*2*/
- windtemp=last; /* start from end*/
- while(windtemp->last!=NULL) /* find first window*/
- { windtemp=windtemp->last;}
- i=1;
- if(i<windtemp->wnumber) /* is spot first link*/
- {/*3*/
- windata->wnumber=i;windata->next=windtemp; /* chain new link to old first link*/
- windata->last=windtemp->last; /* NULL end of chain*/
- windtemp->last=windata; /* chain old first link to new*/
- }/*end of if3*/
- else /* if now first link*/
- {/*1*/
- found=FALSE;
- while(found==FALSE) /* get spot for link*/
- {/*1*/
- while(i<=windtemp->wnumber)i++; /* see if link will fit in chain*/
- if(i>windtemp->wnumber && ((windtemp->next==NULL) || i<windtemp->next->wnumber))
- { /*4*/ /* link fit */
- windata->wnumber=i;windata->next=windtemp->next; /* add link to chain*/
- windata->last=windtemp;
- if(windtemp->next!=NULL) /* if not end*/
- {/*5*/ /* fits between links*/
- windtemp2=windtemp->next;
- windtemp2->last=windata;
- }/*end of if5*/
- windtemp->next=windata;
- found=TRUE; /* found spot*/
- }/*end of if4*/
- else /* fits at end of chain*/
- {/*2*/
- windtemp=windtemp->next; /* no fit get next link in chain*/
- }/*end of else2*/
-
- }/*end of while1*/
- }/*end of else1*/
- }/*end of if2*/
- else windata->wnumber=1; /* first window*/
- if(windata->next==NULL)last=windata; /* if new window is last keep track*/
- present=windata; /* set present to window now in*/
- }/*end of save*/
-
- /*****************************************************************************/
- /* Function window() is to create the window all that is needed */
- /* is to set up the upper left corner, the bottom right corner, */
- /* the border color (background-foreground), you should allready */
- /* have used set_color(background|foreground) for the window */
- /* itself. If a window can not be created window() will pass */
- /* back 0, if the window was created the window number will be */
- /* passed back. */
- /* If the window is to small it will not be allowed to fave a */
- /* border, the window with or without a border must be at least */
- /* one character space in size. All window are chained together */
- /* by pointers and you can move from one window to another. */
- /* window(0,0,24,79,1,0x70); */
- /*****************************************************************************/
-
- int window(char xb,char yb,char xe,char ye,char bdr,unsigned char bdcolor)
- {
- /*
- 0; { No border } For a border type pass one of
- 1; { Single border } the 13 different border numbers
- 2; { Double border }
- 3; { Mixed border }
- 4; { Mixed2 border }
- 5; { Solid border }
- 6; { Light hatch border }
- 7; { Medium hatch border }
- 8; { Dense hatch border }
- 9; { Mixed3 border }
- 10; { Mixed4 border }
- 11; { Mixed5 border }
- 12; { Mixed6 border }
- 13; { Mixed7 border }
- */
-
- int out;
- unsigned int size; /*size of window*/
- int far *address; /*address of window on screen*/
- char far *tempdata,char_address;
- int t,x,y,c,border;
- unsigned char border_char[13][8]={
- {'┌','┐','└','┘','─','─','│','│'}, /* single */
- {'╔','╗','╚','╝','═','═','║','║'}, /* double */
- {'╒','╕','╘','╛','═','═','│','│'}, /* mixed */
- {'╓','╖','╙','╜','─','─','║','║'}, /* mixed2 */
- {'█','█','█','█','█','█','▌','▐'}, /* solid */
- {'░','░','░','░','░','░','░','░'}, /* lhatch */
- {'▒','▒','▒','▒','▒','▒','▒','▒'}, /* mhatch */
- {'▓','▓','▓','▓','▓','▓','▓','▓'}, /* dhatch */
- {0xdf,0xdf,0xdc,0xdc,0xdf,0xdc,0xdd,0xde}, /* mixed3 */
- {0xda,0xbf,0xc0,0xd9,0xdf,0xdc,0xdd,0xde}, /* mixed4 */
- {0xda,0xbf,0xc0,0xd9,0xdb,0xdb,0xdb,0xdb}, /* mixed5 */
- {0xc9,0xbb,0xc8,0xbc,0xdf,0xdc,0xdd,0xde}, /* mixed6 */
- {0xc9,0xbb,0xc8,0xbc,0xdb,0xdb,0xdd,0xde} /* mixed7 */
- };
- curoff();
- /* if(ye>=num_col-1){ye=num_col-1;} /* check to see if the */
- if (xb>xe) {t=xb;xb=xe;xe=t;} /* window begining is */
- if (yb>ye) {t=yb;yb=ye;ye=t;} /* not after end */
- rowb=xb;
- colb=yb;
- rowe=xe;
- cole=ye;
- border=bdr;
- if(rowb+2>rowe){border=0;}
- if(colb+2>cole){border=0;}
-
- row=rowb;col=colb;
- size=(rowe-rowb+1)*(cole-colb+1)*2; /* check memory for room */
- if(farcoreleft() < 1000+size+sizeof(struct window_data))
- {curon();return(FALSE);} /* pass 0 if no room */
- else /* make window*/
- {/*1*/
- save_window(border,bdcolor,size); /* save old screen and window data */
- clrscr(); /* clear the new window using the color from set_color*/
- if(border>=1) /* if window has a border*/
- {/*end of else 1*/
- --border;
- for(row=rowb;row<=rowe;++row) /* draw border */
- {/*1*/
- if(rowb<row&&rowe>row) /* draw mid section of window*/
- {/*1*/
- for (y=0, col=colb;y<=1;y++,col=cole) /* to end of line*/
- {/*2*/
- if(col==colb) /* if first collum */
- {/*3*/
- c=(int)border_char[border][6]; /* c=left side */
- }/*end of if3*/
- else /* display right side */
- {/*2*/
- c=(int)border_char[border][7]; /* c=right side */
- }/*end of else2*/
- address = screenbase + ((row * num_col) + col);
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);} /* if no snow*/
- else output(address,c,1); /* if snow*/
- }/*end of for2*/
- continue; /* do next row*/
- }/*end of if2*/
-
- if(row==rowb) /* draw top line*/
- {/*4*/
- for (col=colb;col<=cole;++col) /* to end of line*/
- {/*3*/
- if(col==colb) /* if left corner*/
- { /*5*/
- c=(int)border_char[border][0]; /* c=left corner*/
- }/*end of if5*/
- else /* mid section*/
- {/*3*/
- c=(int)border_char[border][4]; /* c=mid section*/
- }/*end of else3*/
- if(col==cole) /* if right corner*/
- {/*6*/
- c=(int)border_char[border][1]; /* c=right corner*/
- }/*end of if6*/
- address = screenbase + ((row * num_col) + col); /* address where to put character*/
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);} /* if no snow use this*/
- else output(address,c,1); /* moniter has snow */
- }/*end of for3*/
- continue; /* draw next row*/
- }/*end of if4*/
-
- if(row==rowe) /* draw bottom line*/
- {/*7*/
- for (col=colb;col<=cole;++col) /* to end of line*/
- {/*4*/
- if(col==colb) /* if left corner*/
- {/*8*/
- c=(int)border_char[border][2]; /* c= bottom left corner*/
- }/*end of if8*/
- else /* if mid section*/
- {/*4*/
- c=(int)border_char[border][5]; /* c=mid section*/
- }/*end of else4*/
- if(col==cole) /* if right side*/
- {/*9*/
- c=(int)border_char[border][3]; /* c=bottom right corner*/
- }/*end of if9*/
- address = screenbase + ((row * num_col) + col); /* address where to put c*/
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);}/* no snow*/
- else output(address,c,1); /* snow*/
- }/*end of for4*/
- }/*end of if7*/
- }/*end of for1*/
- ++border; /* restore border*/
- }/*end of if1*/
-
- if(border>=1) /* if window has a*/
- { /*10*/ /* border shrink*/
- ++rowb; /* window to fit*/
- ++colb;
- --rowe;
- --cole;
- }/*end of if10*/ /* put cursor in */
- row=rowb;col=colb; /* right hand top */
- set_cur(rowb,colb); /* corner*/
- present->wcurr = row;
- present->wcurc = col;
- }/*end of else1*/
- curon();
- return(present->wnumber);
- }/*end of window()*/
-
-
-
-
- /*****************************************************************************/
- /* delete_window() will delete any window that you are not presently in. The */
- /* only time you can delete a window that you are is when you are at the end */
- /* of the chain and pass 0 to delete_window(0); . This will delete the end */
- /* window (link) and put you in the new end window (link). */
- /* delete_window is not smart yet so, if a window is on top of the window you*/
- /* delete the old data will be placed over the top window, so you must keep */
- /* track of the windows your self. */
- /* if window is not found 0 will be pass back and if window was deleted a -1 */
- /* will be returned. */
- /* You MUST use option 0 to delete the last window. */
- /* delete_window(5); */
- /*****************************************************************************/
-
- int delete_window(unsigned short wnum)
- {
- int far *windstore; /* pionters to save area*/
- int far *temp;
- unsigned int size;
- int x,y;
- unsigned short srowb,scolb,srowe,scole,
- snum_col,store_size;
- struct window_data far *windata; /* pionters to the window struct*/
- curoff();
- if(number_of_windows>0) /* if 0 no windows*/
- {/*1*/
- present->wcurr=row; /* save curser of present window*/
- present->wcurc=col;
- if(wnum>0) /* if not 0 find window to*/
- {/*2*/ /* delete*/
- windata=present; /* if not same as present*/
- if(windata->wnumber!=wnum) /* find*/
- {/*3*/
- if(windata->wnumber>wnum) /* go back*/
- {/*4*/
- while(windata->last!=NULL && windata->wnumber!=wnum) /* and find window or end of chain*/
- {windata=windata->last;}
- if(windata->wnumber!=wnum)return(FALSE); /* was window found or NULL if NULL return 0*/
- }/*end of if4*/
- else /* check to end*/
- {/*1*/ /*go fowards*/
- while(windata->next!=NULL && windata->wnumber!=wnum)
- {windata=windata->next;}
- if(windata->wnumber!=wnum)return(FALSE); /* if not found return -1*/
- }/*end of else1*/
- }/*end of if3*/
- else {curon();return(FALSE);} /* if same window, can not delete same window*/
- }/*end of if2*/ /* that you are on with this option*/
- else if(wnum==0)windata=last; /* used option 0 delete last window*/
- if(wnum>=0) /* delete window if a positive number*/
- {/*5*/
- if(last==windata)last=windata->last; /*set last window if new*/
- windstore=windata->addressave; /*get address of saved screen*/
- srowb=windata->wrowb;scolb=windata->wcolb; /*restore window data*/
- srowe=windata->wrowe;scole=windata->wcole;
- snum_col=windata->wnum_col;
- store_size=((scole-scolb)+1);
- for(row=srowb;row<=srowe;row++) /* restore screen */
- { /*1*/
- temp=screenbase+((row * snum_col) + scolb); /* address of screen pos*/
- if(fast==TRUE) {fscreen(temp,windstore,store_size);}/* no snow*/
- else screen_in(temp,windstore,store_size); /* snow*/
- windstore+=store_size; /* next line*/
- }/*end of for1*/
-
- }/*end of if5*/
- /* if last window was deleted*/
- if(wnum==0 && last!=NULL) /* restore if option 0*/
- {/*6*/ /* and window to restore*/
- present=last ; /* present window is last window*/
- wcolor=present->wcolor; /* get setup of*/
- rowb=present->wrowb;colb=present->wcolb; /* new present */
- rowe=present->wrowe;cole=present->wcole; /* window*/
- page=present->wpage;num_col=present->wnum_col;
- screenbase=present->screenbase;
- row=present->wcurr; col=present->wcurc;
- set_cur(row,col);
- if(present->bd>=1) /* if border shrink*/
- {/*7*/ /* window*/
- ++rowb;
- ++colb;
- --rowe;
- --cole;
- }/*end of if7*/
- }/*end of if6*/
-
-
-
- if(windata->next!=NULL && windata->last!=NULL) /* relink chain*/
- {/*8*/
- windata->last->next=windata->next;
- windata->next->last=windata->last;
- }/*end of if8*/
- else
- {/*3*/
- if(windata->last==NULL && windata->next!=NULL) /* or NULL end*/
- {windata->next->last=NULL;}
- if(windata->next==NULL && windata->last!=NULL)
- {windata->last->next=NULL;}
- }/*end of else3*/
-
- farfree(windata); /* free momory*/
- number_of_windows--; /* dec number of windows*/
- if(number_of_windows==0) /* if last windo restore*/
- {/*9*/ /* screen data*/
- num_col=fnum_col;
- page=fpage;
- row=frow;col=fcol;
- rowb=frowb;colb=fcolb;
- rowe=frowe;cole=fcole;
- screenbase=fscreenbase;
- wcolor=fcolor;
- set_cur(row,col);
- }/*end of if9*/
-
- }/*end of if1*/
- curon();
- return(TRUE);
- }/*end of main*/
-
-
-
- /*****************************************************************************/
- /* To change to another window all you have to do is pass the window number */
- /* assigned to it when make. If you can move to the window a -1 will be */
- /* passed back else a 0 if not. */
- /* change_window(5); */
- /*****************************************************************************/
-
- change_window(unsigned short wnum)
- {
- unsigned short num;
- struct window_data far *windo,far *windata;
- windata=present;
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- windata->wcurr = reg.h.dh; /* update this window struct*/
- windata->wcurc = reg.h.dl; /* befor moving*/
- if(windata->wnumber!=wnum) /* find new window*/
- {
- if(windata->wnumber>wnum) /* is window you are at after*/
- { /* window you need*/
- while(windata->last!=NULL&&windata->wnumber!=wnum)
- {windata=windata->last;} /* move back*/
- if(windata->wnumber!=wnum)return(FALSE); /* if not found return false*/
- }
- else
- { /* window is befor window you need*/
- while(windata->next!=NULL&&windata->wnumber!=wnum)
- {windata=windata->next;} /* get next window*/
- if(windata->wnumber!=wnum)return(FALSE); /* not found*/
- }
- present=windata; /* found window*/
- row=windata->wcurr; col=windata->wcurc; /* get cursor data*/
- set_cur(row,col); /* set cursor*/
- wcolor=windata->wcolor;
- rowb=windata->wrowb;colb=windata->wcolb; /* restore window data*/
- rowe=windata->wrowe;cole=windata->wcole;
- page=windata->wpage;num_col=windata->wnum_col;
- screenbase=windata->screenbase;
- if(windata->bd>=1) /* if a border make window fit*/
- {
- ++rowb;
- ++colb;
- --rowe;
- --cole;
- }
- }
- return(TRUE);
- }
-
- /*****************************************************************************/
- /* To write to a window or screen you must run moniter() once to set up for */
- /* wprintf() to work. you set the color with set_color() and can put the */
- /* cursor where you want by wset_cur() or set_cur(). wprintf() will check for */
- /* cr ,lf and 0 to give you a crlf or find the end of a string. If you want */
- /* to a formated string use sprintf() first then wprintf(). */
- /* wprintf(" This is a test \n"); */
- /* or */
- /* sprint(ch," %d %f ",dec,flt); */
- /* wprintf(ch); */
- /*****************************************************************************/
-
- void wprintf(char *string, ...)
- {
- int far *address;
- int data;
- int j,x,string_length,
- line_feed=FALSE;
- char strbuff[140];
- va_list ap;
- va_start( ap, string);
- vsprintf(strbuff, string, ap);
- va_end( ap);
- string = strbuff;
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- row = reg.h.dh; /* so we know where to print*/
- col = reg.h.dl; /* string on screen*/
- curoff();
- address = screenbase + ((row * num_col) + col); /* address of screen*/
- string_length = strlen(string); /* string length*/
- for (j = string_length; j >0;--j) /* output until end of string*/
- {
- if(*string == 0x0a||*string == 0x0d) /* check for CR or LF*/
- {line_feed=TRUE;}
- else
- {
- if ((col == (cole+1)) && (row == rowe)) /* if end of window*/
- { /* scroll*/
- scroll();
- } /*end of if*/
- line_feed=FALSE;
- address = screenbase + ((row * num_col) + col);
- data=(wcolor<<8)|*string++;
- if(fast==TRUE) {foutput(address,data,1);} /* put data in screen*/
- else output(address,data,1); /* memory*/
- *address++;
- } /*end of else*/
- if ((col == cole)&&(row != rowe)) /* if end of line */
- { /* new line*/
- ++row;col = colb;
- }/*end of if*/
- else col++;
-
- if (line_feed )
- {
- if(row != rowe) /* check for end of window*/
- {
- col = colb;
- row++;
- *string++;
- line_feed=FALSE;
- }
- else /* if end scroll*/
- {
- scroll();
- *string++;
- line_feed=FALSE;
- } /*e f else*/
- }/*end of if*/
- }/*end of for*/ /* if line feed*/
- curon();
- set_cur(row,col); /* place cursor*/
- }
-
- /*****************************************************************************/
- /* To title a window all you need to do is pass a string that you want to be */
- /* put in the midle of the top border and the color you want the title. */
- /* titlef(" HELP WINDOW "); */
- /*****************************************************************************/
-
- void titlef(char *string,unsigned short color)
- {
- int far *address;
- unsigned short rowt,colt,colort,rb,cb,ce;
- rowt=row;colt=col; /* save cursor*/
- colort=wcolor; /* and color*/
- wcolor=color;
- rb=present->wrowb,cb=present->wcolb;ce=present->wcole; /* find middle of windo*/
- set_cur(rb,cb+(((ce-cb)-strlen(string))/2)+1); /* place string*/
- wprintf(string);
- wcolor=colort; /* restore cursor*/
- row=rowt;col=colt; /* and color*/
- set_cur(row,col); /* put cursor back*/
- }
-
- /*****************************************************************************/
- /* readf() will read from the the console to the end of the window. */
- /* you must declare a buffer[] string and must be at least 1 bigger then the */
- /* window. window() will return the length of the string read and 0 term. */
- /* char buffer[11]; */
- /* readf(buffer); */
- /*****************************************************************************/
- readf(unsigned char *buff)
- {
- unsigned short colw,x,size,length;
- int s;
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- col = reg.h.dl;
- row = reg.h.dh;
- buff[0]=(unsigned int)((cole+1)-col); /* set size of buffer in [0]*/
- sreg.ds=_DS; /* seg of buffer*/
- reg.x.dx=(unsigned)buff; /* offset in dx*/
- reg.h.ah=10; /* read kb*/
- int86x(0x21,®,®,&sreg);
-
- length=buff[1]; /* length read in*/
- for(x=0;x<length;buff[x]=buff[x+2],x++);buff[x+2]=0; /* shift left by 2*/
- buff[length]='\0'; /* NULL end of buffer*/
- set_cur(row,(col+length)); /* set cursor*/
- return(length);
- }
-
- /****************************************************************************/
- /* freadf() is the same as readf() only you tell it the size of input string*/
- /* freadf(buffer,10); */
- /****************************************************************************/
-
- freadf(unsigned char *buff,int s)
- {
- unsigned short colw,x,size,length;
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- col = reg.h.dl;
- row = reg.h.dh;
- if(s==0) /* if not formatted */
- buff[0]=(unsigned int)((cole+1)-col); /* set size of buffer in [0]*/
- else /* formatted read*/
- {
- if(s<=((cole+1)-col)) buff[0]=s+1;
- else buff[0]=(unsigned int)((cole+1)-col);
- }
- sreg.ds=_DS; /* seg of buffer*/
- reg.x.dx=(unsigned)buff; /* offset in dx*/
- reg.h.ah=10; /* read kb*/
- int86x(0x21,®,®,&sreg);
-
- length=buff[1]; /* length read in*/
- for(x=0;x<length;buff[x]=buff[x+2],x++);buff[x+2]=0; /* shift left by 2*/
- buff[length]='\0'; /* NULL end of buffer*/
- set_cur(row,(col+length)); /* set cursor*/
- return(length);
- }
-
-
- /*****************************************************************************/
- /* ega mode are */
- /* mode display display pages colors resolution char_h/v char_size */
- /* 0 text color 8 16 320x200 40x25 8x8 */
- /* 1 text enhance 8 16/64 320x200 40x25 8x14 */
- /* 2 " color 8 16 640x200 80x25 8x8 */
- /* 3 " enhance 8 16/64 640x350 " 8x14 */
- /* 4/5 graph c/e 1 4 320x200 40x25 8x8 */
- /* 6 graph c/e 1 2 640x200 80x25 8x14 */
- /* 7 test mono 8 4 720x350 80x25 9x14 */
- /* 13 graph c/e 2,4,8 16 320x200 40x25 8x8 */
- /* 14 " " 1,2,4 16 640x200 80x25 8x8 */
- /* 15 " mono 1,2 4 640x350 80x25 8x14 */
- /* 16 " enhance 1,2 16/64 640x350 80x25 8x14 */
- /****************************************************************************/
-
-
-
- setmode(int mode) /* set mode as passed*/
- {
- reg.h.al = mode;
- reg.h.ah =0;
- int86(0x10,®,®);
- }
-
-
- int getmode()
- {
- reg.h.al = 0;
- reg.h.ah =0x0f;
- int86(0x10,®,®); /* pass back mode*/
- return(reg.h.al);
- }
-
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- output(int far * dest,int sour,int times)
- {
- asm LES DI,dest /* ES:DI = DEST */
- asm lea si,sour /* SI = data ADDRESS*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- asm MOV DX,03DAH /* Point DX to status port*/
- nextchar:
- asm lodsw
- asm MOV BX,AX /* Store video word in BX*/
- asm MOV AH,09H /* Move horizontal & vertical*/
-
- waith:
- asm IN AL,DX /* Get 6845 status*/
- asm test AL,1 /* Wait horizontal OFF*/
- asm JNZ waith /* retrace*/
-
- asm CLI /* No interrupts now*/
- waitv:
- asm IN AL,DX /* Get 6845 status again*/
- asm and AL,AH /* Wait horizonal ON*/
- asm JZ waitv /* retrace*/
-
- asm MOV AX,BX /* Move word back to AX...*/
- asm STOSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
- asm loop nextchar
- }/* end of output*/
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- foutput(int far * dest,int sour,int times)
- {
- asm LES DI,dest /* DS:SI will DEST*/
- asm lea si,sour /* SI = data ADDRESS*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- nextchar:
- asm lodsw
- asm STOSW /* and then to screen*/
- asm loop nextchar
- }/* end of output*/
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- screen_in(int far * dest,int far *sour,int times)
- {
- asm push ds /* SAVE DS*/
- asm LES DI,dest /* ES:DI WILL POINT TO DEST*/
- asm lds si,sour /* DS:SI WILL POINT TO SOURCE*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- asm MOV DX,03DAH /* Point DX to status port*/
- nextchar:
- asm lodsw
- asm MOV BX,AX /* Store video word in BX*/
- asm MOV AH,09H /* Move horizontal & vertical*/
-
- waith:
- asm IN AL,DX /* Get 6845 status*/
- asm test AL,1 /* Wait horizontal OFF*/
- asm JNZ waith /* retrace*/
-
- asm CLI /* No interrupts now*/
- waitv:
- asm IN AL,DX /* Get 6845 status again*/
- asm and AL,AH /* Wait horizonal ON*/
- asm JZ waitv /* retrace*/
-
- asm MOV AX,BX /* Move word back to AX...*/
- asm STOSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
- asm loop nextchar
- asm pop ds /* RESTORE DS*/
- }/* end of output*/
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- screen_out(int far *dest,int far *sour,int times)
- {
- asm push ds
- asm LES DI,dest /* ES:DI will point to SOUCE*/
- asm lds si,sour /* DS:SI WILL POINT TO DEST*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- asm MOV DX,03DAH /* Point DX to status port*/
- nextchar:
-
- asm MOV AH,09H /* Move horizontal & vertical*/
-
- waith:
- asm IN AL,DX /* Get 6845 status*/
- asm test AL,1 /* Wait horizontal OFF*/
- asm JNZ waith /* retrace*/
-
- asm CLI /* No interrupts now*/
- waitv:
- asm IN AL,DX /* Get 6845 status again*/
- asm and AL,AH /* Wait horizonal ON*/
- asm JZ waitv /* retrace*/
-
- asm lodsw
- asm STOSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
- asm loop nextchar
- asm pop ds /* RESTORE DS*/
- }/* end of output*/
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- screen(int far * dest,int far *sour,int times)
- {
- asm push ds /* SAVE DS*/
- asm LES DI,dest /* ES:DI will point to St[0]*/
- asm lds si,sour /* DS:SI = SOUR*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- asm MOV DX,03DAH /* Point DX to CGA status port*/
- nextchar:
- asm MOV AH,09H /* Move horizontal & vertical*/
-
- waith2:
- asm IN AL,DX /* Get 6845 status*/
- asm test AL,1 /* Wait horizontal OFF*/
- asm JNZ waith2 /* retrace*/
-
- asm CLI /* No interrupts now*/
- waitv2:
- asm IN AL,DX /* Get 6845 status again*/
- asm and AL,AH /* Wait horizonal ON*/
- asm JZ waitv2 /* retrace*/
-
- asm LODSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
-
- asm MOV BX,AX /* Store video word in BX*/
- asm MOV AH,09H /* Move horizontal & vertical*/
-
- waith:
- asm IN AL,DX /* Get 6845 status*/
- asm test AL,1 /* Wait horizontal ON*/
- asm JNZ waith /* retrace*/
-
- asm CLI /* No interrupts now*/
- waitv:
- asm IN AL,DX /* Get 6845 status again*/
- asm and AL,AH /* Wait horizonal OFF*/
- asm JZ waitv /* retrace*/
-
- asm MOV AX,BX /* Move word back to AX...*/
- asm STOSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
- asm loop nextchar
- asm pop ds /* RESTORE DS*/
- }/* end of output*/
-
- /****************************************************************************/
- /* used by window */
- /****************************************************************************/
-
- fscreen(int far * dest,int far *sour,int times)
- {
- asm push ds /* SAVE DS*/
- asm LES DI,dest /* ES:DI IS DEST*/
- asm lds si,sour /* DS:SI IS SOUR*/
- asm mov cx,[times]
- asm CLD /* Set direction to forward*/
- asm MOV DX,03DAH /* Point DX to CGA status port*/
- nextchar:
- asm CLI /* No interrupts now*/
- asm LODSW /* and then to screen*/
- asm STOSW /* and then to screen*/
- asm STI /* Allow interrupts!*/
- asm loop nextchar /* LOOP IF MORE*/
- asm pop ds /* RESTORE DS*/
- }/* end of output*/